import path from 'path'
import express from "express";
const router = express.Router();
import config from "../config/config";
const app = new express();
const server = require('http').createServer(app);

/**
 * 处理跨域问题
 */
app.all('*', function(req, res, next) {
  res.header("Access-Control-Allow-Origin", "*");
  res.header('Access-Control-Allow-Headers', 'Content-type');
  res.header("Access-Control-Allow-Methods", "PUT,POST,GET,DELETE,OPTIONS,PATCH");
  res.header('Access-Control-Max-Age',1728000);//预请求缓存20天
  next();  
});

//bodyparser中间件
const bodyParser = require("body-parser");
app.use(bodyParser.json()); // for parsing application/json
app.use(bodyParser.urlencoded({ extended: true })); // for parsing application/x-www-form-urlencoded
/**
 * 将server/api下的接口全部引入app
 */
// import importer from '../libs/importer';
// const fileDisplays=new importer();
// fileDisplays.setApi(path.join(__dirname,'./server/api'),app)

app.use(express.static(path.join(__dirname, "..","public")));
app.use('/v1',require('./api/userManage'))
// app.use('/v1',require('./api/pgSql.js'))
app.use('/v1',require('./api/baiduTrans'))
// app.use('/v1',require('./api/socketIo'))

//配置静态页面访问路径


var mongoose=require('mongoose');
var options={
    keepAlive:1,
    useMongoClient: true
};
mongoose.Promise = global.Promise;
mongoose.connect('mongodb://localhost:27017/hello');
var db = mongoose.connection;
//var db=mongoose.createConnection('mongodb://localhost:27017/gomall');
db.on('error', function(e) {console.log(e)});
db.once('open',function (){
    console.log("数据库链接成功"); //gang cai hai nneg dakai

});

//启动服务器
server.listen(config.port, function() {
  console.log("server listen on : http://" + config.host + ":" + config.port);
});


import socketIo from './api/socketIo';
const Io=new socketIo();
Io.start(server);

